//
//  EFANoticePubCCell.m
//  efairy
//
//  Created by XiangDongMBP on 2017/8/29.
//  Copyright © 2017年 East. All rights reserved.
//

#import "EFANoticePubCCell.h"
#import "EFAModel.h"
#import "UIColor+XDHex.h"
#import <UIImageView+WebCache.h>

@interface EFANoticePubCCell ()
@property (nonatomic, strong) UIImage *defaultImg;
@property (nonatomic, strong) UIImage *addImg;
@end

@implementation EFANoticePubCCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.defaultImg = [UIImage imageNamed:@"global_img_default"];
    self.addImg = [UIImage imageNamed:@"app_not_add"];
    
//    self.contentView.backgroundColor = [UIColor whiteColor];
    self.contentImgView.layer.borderColor = [UIColor xd_colorWithHex:0xCCCCCC].CGColor;
    [self.closeBtn addTarget:self action:@selector(closeBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)closeBtnTapped:(UIButton *)btn {
    if ([self.delegate respondsToSelector:@selector(noticePubCCell:closeBtnTapped:)]) {
        [self.delegate noticePubCCell:self closeBtnTapped:btn];
    }
}

- (void)configViewWithNotPubItem:(EFANotPubItem *)item {
    if (item) {
        self.contentImgView.image = item.img;
        self.contentImgView.contentMode = UIViewContentModeScaleAspectFill;
        self.contentImgView.layer.borderWidth = 0;
        self.closeBtn.hidden = NO;
    } else {
        self.contentImgView.image = self.addImg;
        self.contentImgView.contentMode = UIViewContentModeCenter;
        self.contentImgView.layer.borderWidth = 1;
        self.closeBtn.hidden = YES;
    }
}

@end

@implementation EFANoticePubCCell (DevicePublishRelative)
- (void)configViewWithDevPubItem:(EFADevPubItem *)item {
    if (item) {
        if (item.image_url.length) {
            [self.contentImgView sd_setImageWithURL:[NSURL URLWithString:item.image_url] placeholderImage:self.defaultImg];
        } else {
            self.contentImgView.image = item.img;
        }
        self.contentImgView.contentMode = UIViewContentModeScaleAspectFill;
        self.contentImgView.layer.borderWidth = 0;
        self.closeBtn.hidden = !item.canEdit;
    } else {
        self.contentImgView.image = self.addImg;
        self.contentImgView.contentMode = UIViewContentModeCenter;
        self.contentImgView.layer.borderWidth = 1;
        self.closeBtn.hidden = YES;
    }
}
@end

